﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace WPFSolution
{
    /// <summary>
    /// Interaction logic for MenuWindow.xaml
    /// </summary>
    /// 
    public partial class MatrixWindow : Window
    {
        public MatrixWindow()
        {
            InitializeComponent();
        }

        #region StatusBar Operations

        private void SwitchStatusBarBindings(TabItem selectedTab)
        {
            switch (selectedTab.Name)
            {
                case ("StatisticsTabItem"):
                    var statisticsStatusBinding =
                        new Binding
                        {
                            Source = StatisticsControl,
                            Path = new PropertyPath("StatusString"),
                            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                        };
                    BindingOperations.ClearBinding(StatusBarLabel, ContentProperty);
                    StatusBarLabel.SetBinding(ContentProperty, statisticsStatusBinding);
                    break;
                case ("MatrixCalculatorTabItem"):
                    var matrixManipulatorStatusBinding =
                        new Binding
                        {
                            Source = MatrixManipulator,
                            Path = new PropertyPath("StatusString"),
                            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                        };
                    BindingOperations.ClearBinding(StatusBarLabel, ContentProperty);
                    StatusBarLabel.SetBinding(ContentProperty, matrixManipulatorStatusBinding);
                    break;
                case ("LargeDimentionTabItem"):
                    var largeDimentionMatrixSolverStatusBinding =
                        new Binding
                        {
                            Source = largeDimentionMatrixSolver,
                            Path = new PropertyPath("StatusString"),
                            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                        };
                    BindingOperations.ClearBinding(StatusBarLabel, ContentProperty);
                    StatusBarLabel.SetBinding(ContentProperty, largeDimentionMatrixSolverStatusBinding);
                    break;
                default:
                    BindingOperations.ClearBinding(StatusBarLabel, ContentProperty);
                    break;
            }

        }
        #endregion
        private void mainTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MatrixManipulator != null)
                SwitchStatusBarBindings((TabItem)mainTabControl.SelectedItem);
        }

    }
}
